package com.hyl.boottest.service;

import com.hyl.boottest.mapper.ReturnPersonMapper;
import com.hyl.boottest.util.PageUtil;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.hyl.boottest.entity.ReturnPerson;

import java.util.List;

@Service
public class ReturnPersonServiceImpl implements ReturnPersonService {
	@Resource
	private ReturnPersonMapper returnPersonMapper;

	public int insert(ReturnPerson record) {
		return returnPersonMapper.insert(record);
	}

	public ReturnPerson selectById(Integer id) {
		return returnPersonMapper.selectById(id);
	}

	public int updateById(ReturnPerson record) {
		return returnPersonMapper.updateById(record);
	}

	@Cacheable(value = "findByPage",key = "#returnDate")
	public PageUtil<ReturnPerson> listPage(String returnDate, Integer currentPage, Integer showSize){
		//计算偏移量
		Integer offSet = (currentPage-1) * showSize;//分页的偏移量
		//获取数据
		List<ReturnPerson> list = returnPersonMapper.findByPage(returnDate, offSet, showSize);
		//总行数
		int total = returnPersonMapper.findCount(returnDate);
		//封装==》响应给前台
		PageUtil<ReturnPerson> pageUtil = new PageUtil<>(list, currentPage, showSize, total);
		return  pageUtil;
	}



}

